package com.jic.interaction.cardCouponPlatform.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jic.common.base.vo.RestResult;
import com.jic.interaction.cardCouponPlatform.model.entity.CardCouponPlatform;
import com.jic.interaction.cardCouponPlatform.model.entity.OrderCouponPlatform;
import com.jic.interaction.cardCouponPlatform.service.CardCouponPlatformService;
import com.jic.weamop.api.WeAMOPApi;
import com.jic.weamop.request.ChannelResponseApi;
import com.jic.weamop.request.MessageRequestApi;
import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Auther YGH
 * @DATE 2020/11/11/13:44
 */

@Service
@Slf4j
public class CardCouponPlatformServiceImpl implements CardCouponPlatformService {

    @Autowired
    WeAMOPApi weAMOPApi;
    /*
     * @Author chengpunan
     *@Package com.jic.interaction.cardCouponPlatform.service.impl
     *ClassName CardCouponPlatformServiceImpl
     * @Description 下单 //TODO topip: bcces-wbms.0001 调用方式不确定
     * @Date 16:19 2020/11/11
     * @Param CardCouponPlatform 采购商
     * @return 订单编号
     * @Version:1.0
     **/
    @Override
    public String addPlaceAnOrder(CardCouponPlatform cardCouponPlatform) {
        MessageRequestApi message=new MessageRequestApi();
        message.setToTopic("bcces-wbms.0001");
        String param = JSONObject.toJSONString(cardCouponPlatform);
        Map map = JSONObject.parseObject(param,Map.class);
        message.setMessage(JSON.toJSONString(map));
        message.setServiceId("10001");
        RestResult<ChannelResponseApi> channelResponseApiRestResult = weAMOPApi.sendMessage(message);
        return channelResponseApiRestResult.toString();
    }
        /*
         * @Author chengpunan
         *@Package com.jic.interaction.cardCouponPlatform.service.impl
         *ClassName CardCouponPlatformServiceImpl
         * @Description  查询订单//TODO  topip: bcces-wbms.0001 调用方式不确定
         * @Date 16:20 2020/11/11
         * @Param CardCouponPlatform 采购商
         * @return 订单信息 OrderCouponPlatform
         * @Version:1.0
         **/
    @Override
    public String getPlaceAnOrder(OrderCouponPlatform platform) {
        log.info("开始执行 入参{}", JSON.toJSONString(platform));
        MessageRequestApi message=new MessageRequestApi();
        message.setToTopic("bcces-wbms.0003");
        message.setMessage(JSON.toJSONString(platform));
        message.setServiceId("10001");

        log.info("调用消息接口，入参 = {}",JSON.toJSONString(message));
        RestResult<ChannelResponseApi> channelResponseApiRestResult = weAMOPApi.sendMessage(message);
        log.info("调用消息接口，出参 = {}",JSON.toJSONString(message));
        JSONObject ret = JSONObject.parseObject(JSON.toJSONString(channelResponseApiRestResult));

        log.info("结束 返回{}", JSON.toJSONString(channelResponseApiRestResult));
        return channelResponseApiRestResult.toString();
    }


}
